#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>



int main()
{
  int fd[2] = {0};
  if (pipe(fd) < 0) // -1 error
  {
    perror("pipe error!\n");
    return -1;
  }

  pid_t pid = fork();
  if (pid == 0) // child
  {
    close(fd[0]);
    const char* msg = "hello world!\n";
    while (1)
    {
      write(fd[1] ,msg , strlen(msg));
      printf("send success!\n");
      sleep(1);
    }

    // we do not set _exit func there
  }

  // father 
  close(fd[1]);
  sleep(6);
  close(fd[0]);
  int status = 0;
  waitpid(pid , &status ,0);
  printf("wait child process success!\n");
  printf("the singal is : %d\n", status & 0x7f);
  return 0;
}
